<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改网点列表')" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=4IU3oIAMpZhfWZsMu7xzqBBAf6vMHcoa"></script>
    <!-- 如果需要拖拽鼠标进行操作，可引入以下js文件 -->
    <script type="text/javascript" src="http://api.map.baidu.com/library/RectangleZoom/1.2/src/RectangleZoom_min.js"></script>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-shop-edit" th:object="${shop}">
            <input name="shopId" th:field="*{shopId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">网点名称：</label>
                <div class="col-sm-8">
                    <input name="shopName" th:field="*{shopName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">电话：</label>
                <div class="col-sm-8">
                    <input name="shopTel" th:field="*{shopTel}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">地址：</label>
                <div class="col-sm-8">
                    <input id="suggestId" name="shopAddress" th:field="*{shopAddress}" class="form-control" type="text">
                    <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div  class="col-sm-8">
                    <div id="allmap" style="width: 470px;height: 250px;"></div>
                </div>
            </div>
            <div style="display: none" class="form-group">
                <label class="col-sm-3 control-label">经度：</label>
                <div class="col-sm-8">
                    <input name="mapLongitude" th:field="*{mapLongitude}" class="form-control" type="text">
                </div>
            </div>
            <div style="display: none" class="form-group">
                <label class="col-sm-3 control-label">纬度：</label>
                <div class="col-sm-8">
                    <input name="mapLatitude" th:field="*{mapLatitude}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "core/shop";
        $("#form-shop-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-shop-edit').serialize());
            }
        }
    </script>

    <!--百度地图-->
    <script type="text/javascript" th:inline="javascript">

        // 百度地图API功能
        function G(id) {
            return document.getElementById(id);
        }

        var map = new BMap.Map("allmap");
        map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
        map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用
        var myDrag = new BMapLib.RectangleZoom(map, {
            followText: "拖拽鼠标进行操作"
        });
        myDrag.open();  //开启拉框放大
        // myDrag.close();  //关闭拉框放大

        map.centerAndZoom("北京",19);   // 初始化地图,设置城市和地图级别。

        var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
            {"input" : "suggestId"
                ,"location" : map
            });

        ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
            var str = "";
            var _value = e.fromitem.value;
            var value = "";
            if (e.fromitem.index > -1) {
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

            value = "";
            if (e.toitem.index > -1) {
                _value = e.toitem.value;
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
            G("searchResultPanel").innerHTML = str;
        });

        var myValue;
        ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
            var _value = e.item.value;
            myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
            setPlace();
        });

        function setPlace(){
            map.clearOverlays();    //清除地图上所有覆盖物
            function myFun(){
                var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                //设置经纬度
                $("input[name='mapLongitude']").val(pp.lng);
                $("input[name='mapLatitude']").val(pp.lat);
                map.centerAndZoom(pp, 18);
                map.addOverlay(new BMap.Marker(pp));    //添加标注
            }
            var local = new BMap.LocalSearch(map, { //智能搜索
                onSearchComplete: myFun
            });
            local.search(myValue);
        }
    </script>

</body>
</html>